/**
Copyright 2011 Patrick Devaney

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <iostream>
using namespace std;

// Calculates M as a fraction (not always convenient)
long double calcmfraction(long double x1, long double y1, long double x2, long double y2) {
long double a;
long double b;
string m;
a = y2 - y1;
b = x2 - x1;

cout << a << endl << "-" << endl << b << endl;
}


// Calculates a simplified M (not always accurate)
long double calcmsimplified(long double x1, long double y1, long double x2, long double y2) {
long double m;
// Handles cases where calcm = 0
if(x1 == x2) {
	m = 0;
}
// Handles cases where calcm != 0
else {
m = (y2 - y1) / (x2 - x1);
}
return m;
}

// The I/O plugin main.cpp uses
// Variables lower-case and have the "calc" prefix so I
// have peace of mind that no names will conflict/bug
long double calcx1, calcy1, calcx2, calcy2, calcm;
// The function to calculate M
int mcalcxyplugin(void) {
// The basic I/O stuff
cout << "(X1, Y1)" << endl << "What is the value of X1?" << endl;
cin >> calcx1;
cout << "What is the value of Y1?" << endl;
cin >> calcy1;
cout << "(X2, Y2)" << endl << "What is the value of X2?" << endl;
cin >> calcx2;
cout << "What is the value of Y2?" << endl;
cin >> calcy2;

cout << endl << "The value of M is:" << endl << endl << "As a fraction:"
<< endl;
calcmfraction(calcx1, calcy1, calcx2, calcy2);
calcm = calcmsimplified(calcx1, calcy1, calcx2, calcy2);
cout << "Simplified:" << endl << endl << calcm << endl << endl << "Note:"
" you should verify this number by manually simplifying the fraction above,"
<< endl << "as this simplification has been known to be inaccurate in some"
<< " cases." << endl;
}